package com.dream.web;


import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.dream.bean.Brand;
import com.dream.service.BrandService;
import com.dream.utils.PageInfo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bruce
 * @since 2018-12-05
 */
@Controller
@Scope("prototype")
@RequestMapping("/brand")
public class BrandController {
	
	@Reference
	BrandService bs;
	
	@RequestMapping("/brandlist/{pageIndex}")
	public String getList(@PathVariable("pageIndex") Integer pageIndex,@RequestParam(defaultValue="5") Integer pageSize,Brand brand,Model model) {
	
		Page<Brand> page = new Page<Brand>(pageIndex, pageSize);
		EntityWrapper<Brand> wrapper = new EntityWrapper<Brand>();
		if(brand!=null && brand.getName()!=null) {
			wrapper.like("name", brand.getName());
		}
		Page<Brand> results = bs.selectPage(page, wrapper);
		List<Brand> brands = results.getRecords();//得到数据
		int totalCount = ((Long)results.getTotal()).intValue();//总数
		boolean hasPrevious = results.hasPrevious();
		boolean hasNext = results.hasNext();
		PageInfo<Brand> pageInfo = new PageInfo<>(totalCount, pageSize, pageIndex, brands, brand);
		model.addAttribute("pageInfo", pageInfo);
	
		return "Brand_Manage";
	}

}

